#!/usr/bin/python
import sys
import os
import time

month_to_number = {
	'Dec' : '12',
}


def parse_month(s):
	return month_to_number[s]
	

def parse_line(s):
	sep = '    '
	s_list = s.split('INFO')	
	date_field = s_list[0]
	date = date_field.split(' ')
	str_date =  date[3]+'-'+ parse_month(date[2]) +'-'+date[1]+' '+date[4]
	ad_field = s_list[1]
	temp = ad_field.split(': ')
	banner_type = temp[0]
	ad_url = temp[1]
	return str_date + sep + banner_type + sep + ad_url

	

def parse_file(source='ads.log.bak', dest='ads.log.txt'):

	log_f = open(source, 'r')
	txt_f = open(dest, 'w')

	while True:
		s = log_f.readline()
	        if len(s) > 0:
			txt_f.write(parse_line(s))
		else:
                	break
	log_f.close()
	txt_f.close()


if __name__ == '__main__':
	parse_file()
